#ifndef MODBUSWRITEINSTRUCTIONLOGIC_H
#define MODBUSWRITEINSTRUCTIONLOGIC_H

#include <QObject>
#include "instructionEnum.h"
#include "GeneralDefine.h"

class ProgramSet;
class ProgramEngine;
class RegData;
class ModbusWrite;

class ModbusWriteInstructionLogic : public QObject
{
    Q_OBJECT

public:
    explicit ModbusWriteInstructionLogic(int robotIdIn,
                                         ProgramSet *programSetIn,
                                         ProgramEngine *programEngineIn,
                                         RegData *regDataIn);

    E_PROGRAM_LOOP_RESULT startModbusWrite(int programNumIn,const ModbusWrite &instructionIn, int lineIndex);

private:
    int writeModbusTcpServer(int portIn, int writeValue, int modbusRegisterAddress);
    int writeModbusTcpClient(QString  ipAndPort, int writeValue, int modbusRegisterAddress);
    int writeModbusRtuClient(int slaveIdIn, int writeValue, int modbusRegisterAddress);


    void addMsg( int messageLevel,
                 std::string componentName,
                 std::string messageType,
                 int messageCode,
                 int robotId,
                 int parameter1 = 0,
                 int parameter2 = 0,
                 int parameter3 = 0,
                 int parameter4 = 0,
                 QString message= "");

private:

    ProgramEngine *programEngine;
    ProgramSet *programSet;
    RegData *regData;
    int robotId;

};

#endif // MODBUSWRITEINSTRUCTIONLOGIC_H
